package server;

/**
 * Diese Klasse stellt das sog. Produkte-Gebinde nach.
 * @author reto
 *
 */
public class ProductLot {
	private Product product;

	private int amount;

	/**
	 * @param product Produkt
	 * @param amount Anzahl
	 */
	public ProductLot(final Product product, final int amount) {
		super();
		this.product = product;
		this.amount = amount;
	}

	/**
	 * 
	 * @return das Produkt
	 */
	public Product getProduct() {
		return this.product;
	}

	/**
	 * 
	 * @return die Anzahl der Produkte in diesem Gebinde
	 */
	public int getAmount() {
		return this.amount;
	}

	/**
	 * 
	 * @param amount Die Anzahl der Produkte in diesem Gebinde
	 */
	public void setAmount(final int amount) {
		this.amount = amount;
	}

	/**
	 * Convenience Methode um das Gebinde um eine Einheit zu erhöhen
	 *
	 */
	public void add() {
		this.setAmount(this.getAmount() + 1);
	}
	
	/**
	 * Convenience Methode um das Gebinde um eine Einheit zu verkleinern
	 *
	 */
	public void remove() {
		this.setAmount(this.getAmount() - 1);
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((this.product == null) ? 0 : this.product.hashCode());
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (this.getClass() != obj.getClass()) {
			return false;
		}
		final ProductLot other = (ProductLot) obj;
		if (this.product == null) {
			if (other.product != null) {
				return false;
			}
		} else if (!this.product.equals(other.product)) {
			return false;
		}
		return true;
	}
	
	@Override
	public String toString() {		
		return this.product.toString()+" ("+this.amount+")";
	}
}
